#include <stdio.h>
#include <cm/struct/cm_fifo.h>
#include <assert.h>

const char *temp_str[] = { "11212", "31234", "12345", "12345", "61234", "56712",
		"34567", "81234", "56789" };

int main(int argc, char **argv)
{
	const unsigned SIZE = 57;
	cmfifo_t *f = cmfifo_create(SIZE);
	if (f == NULL)
		return 0;

	char buffer[10];

	int k;
	int readable = 0;
	for (k = 0; k < 100000; k++) {
		printf("round %d\n", k);
		int i;
		unsigned s, r, n;
		for (i = 1; i < 10; i++) {
			cmfifo_putdata(f, "123456789", i);
			r = cmfifo_readable(f);
			readable += i;
			assert(readable == r);
		}

		for (i = 0; i < 9; i++) {
			cmfifo_getdata(f, buffer, 5);
			readable -= 5;
			r = cmfifo_readable(f);
			buffer[6] = 0;
			assert(readable == r);
			assert(strcmp(temp_str[i], buffer) == 0);
		}

		assert(cmfifo_empty(f));
	}
	cmfifo_destroy(&f);
	return 0;
}

